import axios from "axios";

// GET
export const getExecutingTasksByBossID = bossid => {
  // 参数：发包方id
  return axios.get(
    `/task/boss/executing/${bossid}`
  ).then(res => {
    return res.data;
  });
}

// GET
export const getFinishedTasksByBossID = bossid => {
  // 参数：发包方id
  return axios.get(
    `/task/boss/completed/${bossid}`
  ).then(res => {
    return res.data;
  });
}

// POST
export const releaseTask = payload => {
  return axios.post('/task/create', {
    // bossid: payload.bossid,
    username: payload.username,
    taskname: payload.taskname,
    type: payload.type,
    environment: payload.environment,
    deviceRequirement: {...payload.deviceRequirement},
    deadline: payload.deadline,
    need_num: payload.need_num,
    description: payload.description,
    reportPrice: payload.price
  }).then(res => {
    return res.data;
  });
/*  return new Promise((resolve) => {
    console.log('start creating task:');
    console.log(payload);
    setTimeout(() => {
      console.log('create success!');
      resolve({
        "code": 200,
        "msg": "string",
        "data": {
          "id": 0,
          "userId": 0,
          "taskname": "string",
          "environment": {
            "osList": [
              "string"
            ],
            "minRam": 0,
            "maxRam": 0,
            "processorArchitectureList": [
              "string"
            ]
          },
          "type": "string",
          "startTime": "2022-09-28T10:12:02.437Z",
          "deadline": "2022-09-28T10:12:02.437Z",
          "total_num": 0,
          "need_num": 0,
          "description": "string"
        }
      })
    }, 3000)
  })*/
}

// GET 获取要邀请的工人列表
// todo
export const getWorkersToInviteByTaskID = taskid => {
  return axios.get(
    `/grouprecommend/${taskid}`
    // `https://mock.hmilyld.com/mock/628dff682e51320020c65669/invite/worker-list`
  ).then(res => {
    return res.data;
  })
}

// POST 邀请工人
// todo
export const inviteWorkers = payload => {
  return axios.post(
    `/user/invite`,
    {
      taskid: payload.taskid,
      workeridList: payload.workeridList
    }
  ).then(res => {
    return res.data;
  })
}

//POST 充值
export const balanceRecharge = payload =>{
  const {userId, amount} = payload;
  const type = 'charge';
  return axios
      .post(`/user/charge`,{userId,amount,type})
      .then(res =>{
        return res.data
      })

}
